package windows;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ultrastarography.Song;

public class SongTableModel extends AbstractTableModel {
	private static final long serialVersionUID = -142253274249220800L;
	private static final Logger log = LoggerFactory
			.getLogger(SongTableModel.class);
	private List<Song> songList;

	public SongTableModel(List<Song> songList) {
		this.songList = songList;
	}

	public List<Song> getSongList() {
		return songList;
	}

	public int getRowCount() {
		return songList.size();
	}

	public int getColumnCount() {
		return Song.INFORMATION.length;
	}

	@Override
	public String getColumnName(int column) {
		return Song.INFORMATION[column];
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return true;
	}

	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		if (log.isDebugEnabled()) {
			log.debug("Setting new value '{}' for row '{}' and column '{}'",
					new Object[] { aValue.toString(), rowIndex,
							getColumnName(columnIndex) });
		}

		songList.get(rowIndex).setInformationValue(columnIndex,
				aValue.toString());
		songList.get(rowIndex).setChanged();
		fireTableCellUpdated(rowIndex, columnIndex);
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		return songList.get(rowIndex).getData(columnIndex);
	}

}
